package algorithm;

import bean.Credit_parameter;
import java.util.HashMap;
import java.util.Map;
public class Running_credit {
	
	public static final int running_short = 0;     //短跑
	public static final int running_long = 1;     //长跑
	
	//参数顺序（比赛用时(以秒为单位)，比赛类型，比赛等级，过往成绩）
	public Map<String,Double> Get_running_score(int running_time,int running_level,int running_type,double running_record){
		
		double Get_now_running_result = 0;   //比赛成绩的中间数据
		//比赛规则
		if(running_type == Running_credit.running_long){       //长跑比赛
			
			if(running_time > 7377 && running_time <= 10800){  //7377,10800为比赛记录
				Get_now_running_result = 40 / (10800 - 7377) * (running_time - 7377) + 60; 
			}
			else if(running_time > 10800 && running_time <= 12600){
				Get_now_running_result = 60 /(12600 - 10800) * (running_time - 10800);
			}
			else{
				Get_now_running_result = 0;
				//System.out.println("PARAMETER ERROR !!");
			}
		}
		else if(running_type == Running_credit.running_short){   //短跑比赛
			
			if(running_time < 9.58){
				Get_now_running_result = 0; 
			}
			else if(running_time > 9.58 && running_time <= 12.88){
				Get_now_running_result = 20 / (12.88 - 9.58) *(running_time - 9.58) + 80;
			}
			else if(running_time > 12.88 && running_time <= 14.00){
				Get_now_running_result = 20 / (14.00 - 12.88) * (running_time - 12.88) + 60;
			}
			else if(running_time > 14.00 && running_time <= 16.00){
				Get_now_running_result = 60 / (16.00 - 14.00) * (running_time - 14.00);
			}
			else{
				Get_now_running_result = 0;
			}
		}
		
		//游泳比赛规则
		if(running_level <= Credit_parameter.getMatch_level_1() ){
			running_level = Credit_parameter.getMatch_level_1();
		}
		else if(running_level >= Credit_parameter.getMatch_level_2() && running_level <= Credit_parameter.getMatch_level_1()){
			running_level = Credit_parameter.getMatch_level_2();
		}
		else if(running_level >= Credit_parameter.getMatch_level_3() && running_level <= Credit_parameter.getMatch_level_4()){
			running_level = Credit_parameter.getMatch_level_3();
		}
		else if(running_level >= Credit_parameter.getMatch_level_4()){
			running_level = Credit_parameter.getMatch_level_4();
		}
		
		double running_Credit = ((1 - Credit_parameter.getProfession_running_result_weight()) * running_level + 
				Credit_parameter.getProfession_running_result_weight() * Get_now_running_result) *
				(1 - Credit_parameter.getProfession_running_record_weight());
		double running_Record = Credit_parameter.getProfession_running_record_weight() * running_record + 
				running_Credit;
		Map<String,Double> map = new HashMap<String,Double>();
		map.put("running_credit", running_Credit );
		map.put("running_record",running_Record);
		
		//判断积分是否变化
		if(running_Credit == 0){
			map.put("flag", (double) 0);   //flag标志，0表示积分无变化
		}
		else{
			map.put("flag", (double) 1);   //flag标志，1表示积分有变化
		}
		return map;
	}
}

